package DatabaseImpl;

import java.sql.ResultSet;
import java.util.ArrayList;

import Database.DBconnecter;
import DatabasePO.ClassPO;

public class ClassImpl {
	
	public ArrayList<ClassPO> getClasses(){
		DBconnecter con=new DBconnecter();
		String sql="select * from classB";
		ArrayList<ClassPO> classes=new ArrayList<ClassPO>();
		ResultSet rs=null;
		try{
			con.getDBConnect();
			rs=con.executeQuery(sql);
			rs.first();
			rs.previous();
			while(rs.next()){
				ClassPO c=new ClassPO();
				c.setNumber(rs.getString("id"));
				c.setName(rs.getString("name"));
				c.setTime(rs.getString("time"));
				c.setPoint(rs.getString("point"));
				c.setTeacher(rs.getString("teacher"));
				c.setPlace(rs.getString("place"));
				c.setShare(rs.getString("sh"));
				classes.add(c);				
			}
			rs.close();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return classes;
		
	}
	
	
	public ClassPO getmyClass(String id){
		DBconnecter con=new DBconnecter();
		String sql="select * from classB where id='"+id+"'";
		ResultSet rs=null;
		ClassPO c=new ClassPO();
		try{
			con.getDBConnect();
			rs=con.executeQuery(sql);
			while(rs.next()){
				c.setNumber(rs.getString("id"));
				c.setName(rs.getString("name"));
				c.setTime(rs.getString("time"));
				c.setPoint(rs.getString("point"));
				c.setTeacher(rs.getString("teacher"));
				c.setPlace(rs.getString("place"));
				c.setShare(rs.getString("sh"));		
			}
			rs.close();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return c;
		
	}

	

}
